package com.gzh.core.chche.service;

import com.alibaba.fastjson.JSONObject;
import com.gzh.core.chche.dao.mapper.TshoolMapper;
import com.gzh.core.chche.dao.mapper.TuserMapper;
import com.gzh.core.chche.dao.po.TschoolBeanCache;
import com.gzh.core.chche.dao.po.TschoolEntityCache;
import com.gzh.core.chche.dao.po.TuserBeanCache;
import com.gzh.core.chche.dao.po.TuserEntityCache;
import com.gzh.core.chche.service.dto.School;
import com.gzh.core.chche.service.dto.User;
import com.gzh.core.dao.mapper.UserMapper;
import com.gzh.core.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/*
  @Author guanzh
  @Date 2022/1/4 14:52
  @Description
 */
@Service
public class UserCache extends Cache<User> {
    @Autowired
    private TuserMapper tuserMapper;

    public UserCache() {
        this.cacheKey = "user";
        this.cacheName = "用户信息";
    }

    @Override
    public Map<String, String> loadCacheData(List<String> keyList, String updateTime) {
        TuserBeanCache tuserBeanCache = new TuserBeanCache();
        tuserBeanCache.setUserIdList(keyList);
        List<TuserEntityCache> userList = tuserMapper.queryUser(tuserBeanCache);
        Map<String, String> map = new LinkedHashMap<>();
        for (TuserEntityCache item : userList) {
            User user = new User(item);
            map.put(getKey(user), JSONObject.toJSONString(user));
        }
        return map;
    }

    @Override
    public List<User> getObjectListByKeyword(String findstr) {
        return null;
    }

    @Override
    public String getKey(User user) {
        if (user == null) {
            return "";
        }
        return String.valueOf(user.getUserId());
    }

}
